<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title></title>
  </head>
  <body>
    <button onclick='getByte();'>test_getbyte</button>
    <button onclick='getVariant();'>test_getvariant_int</button>
    <button onclick='getVariantArray();'>test_getvariant_array</button>
    <button onclick='testSafeArray();'>test_safearray</button>
    <button onclick='testRecord();'>test_udt</button>
    <object id="ocx" classid="CLSID:2c9adc93-68c2-41de-8699-fb57860d0e52" codebase="../Debug/MFCActiveXControlTest.ocx"> 
    </object>
  </body>
  <script type="text/javascript">
    function getByte(){
          var retval = ocx.GetByte();
          console.log(retval);
        }
    function getVariant(){
          var retval = ocx.GetVariantInt();
          console.log(retval);
        }
    function getVariantArray(){
          var retval = ocx.GetVariantArray();
          console.log(typeof retval);
          var ret = new VBArray(retval).toArray();
          console.log(retval);
          console.log(ret);
        }
    function getSafeArray(jsArr) {
          var dict = new ActiveXObject("Scripting.Dictionary");
          for (var i = 0; i < jsArr.length; i++)
            dict.add(i, jsArr[i]);
          return dict.Items();
        }
    function getUdt(){
          var udt = ocx.GetMyUdt();
          return udt;
        }
    function testSafeArray(){

          //to a safe array
          var safearr = getSafeArray([11,22,33]);

          console.log(typeof safearr);
          //back to a js array
          var jsArr = new VBArray(safearr).toArray();
          console.log(jsArr);
        }
    function testRecord(){
          var udt = getUdt();
          console.log(typeof udt);
          var ret = new VBArray(udt).toArray();
          console.log(ret);
          var arr = new VBArray(ret[2]).toArray();
          console.log(arr);
        }
  </script>
</html>
